package net.wanho.service.impl;

import net.wanho.dao.UserDao;
import net.wanho.entity.User;
import net.wanho.exception.UsernameExistsException;
import net.wanho.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Author：汤小洋
 * Date：2024-12-11 16:22
 * Description：<描述>
 */
@Service
@Primary
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public void register(String username, String password) {
        if ("tom".equals(username)){
            throw new UsernameExistsException("用户名已存在！");
        }
        userDao.insert(username, password);
    }

    @Override
    public String logout() {

        int i = 5/0;

        return "退出成功";
    }

    @Override
    public List<User> findAll() {
        return userDao.selectAll();
    }


}
